'This code will upload daily currency rates into
'App_Data folder and hence upload to Database.

Imports System.Data.OleDb
Partial Class Default2
    Inherits System.Web.UI.Page
    Protected Sub pbUpload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles pbUpload.Click

        'This section will upload the file to App_Data folder 

        If FlCurrRate.HasFile Then
            Dim Fname1 = FlCurrRate.FileName
            Dim webfolder = Request.MapPath(".")
            Dim appdatafolder = webfolder & "/App_Data/"
            FlCurrRate.SaveAs(appdatafolder & Fname1)
        End If

        'This section will insert the daily rates
        'into the Daily_Rate table

        Dim connect As String
        connect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|AllAboutForexDB.mdb"
        Dim conn As New OleDbConnection(connect)
        Dim path As String = Server.MapPath("App_Data")
        Dim query1 As String = "INSERT INTO Daily_Rate ([Currency], [Rate],[UpldDate]) SELECT Curr, DlyRate, LdDate FROM [Text;DATABASE=" & path & ";].[DailyCurrRate.txt]"
        Dim cmd As OleDbCommand = New OleDbCommand(query1, conn)
        conn.Open()
        cmd.ExecuteNonQuery()
        conn.Close()
        lblFlUpLdSt.Text = "Rates are uploaded Successfully...."
    End Sub
End Class
